package jgl.vajra.management.dialogFragment;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;

import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;

import com.umeng.socialize.media.UMImage;

import jgl.vajra.management.R;
import jgl.vajra.management.databinding.DialogFragmentShareFriendsBinding;
import jgl.vajra.management.manager.AccountManager;
import jgl.vajra.management.manager.UMShareManager;
import jgl.vajra.management.utils.GenerateQRCodeUtils;
import jgl.vajra.management.widget.dialogfragment.BaseDialogFragment;
import jgl.vajra.management.widget.utils.BitmapUtils;
import jgl.vajra.management.widget.utils.UIUtils;

public class ShareFriendsDialogFragment extends BaseDialogFragment<DialogFragmentShareFriendsBinding> {

    private FragmentActivity activity;
    private Context context;

    private String url ="";
    private String title="金钢佬app就近租工程机械又快又省钱";
    private String intro="客户端下载送下单补贴劵200元;  机主端下载送接单补贴劵100元";
    private String image="";
    private int shareLogo=R.drawable.ic_share_logo;

    @Override
    public void initView(Context context, View rootView, AttributeSet attrs) {
        mBinding.setView(this);
        this.context=context;
        setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomSheetEdit);

        url= "http://jinganglao.com/files/#/?invitation=" + AccountManager.getInstance().getLoginData(UIUtils.getContext()).invitation;
        Bitmap bmp = GenerateQRCodeUtils.create2DCode(url);
        GenerateQRCodeUtils.createQRCodeBitmapWithPortrait(context, bmp, R.mipmap.ic_launcher, bmp.getWidth() / 5);
        mBinding.ivQRCode.setImageBitmap(bmp);

        mBinding.tvInvitation.setText("编号: "+AccountManager.getInstance().getLoginData(UIUtils.getContext()).invitation);
    }

    @Override
    public void initData(Context context) {
    }

    @Override
    public void initEvent(Context context) {

    }


    public int getLayoutRes() {
        return R.layout.dialog_fragment_share_friends;
    }


    @Override
    public int getGravity() {
        return Gravity.CENTER;
    }

    public void setShareData(FragmentActivity activity/*, ShareInfoBean infoBean, ShareShowBean showBean, ShareDialogListener listener*/) {
        this.activity = activity;
      /*  this.showBean = showBean;
        this.listener = listener;
        this.shareInfoBean = infoBean;
        this.url = infoBean.link;
        this.title = infoBean.title;
        this.intro = infoBean.intro;
        this.image = infoBean.img;*/
    }

    //保存海报hare-core
    public void onDownloadLocal() {
        BitmapUtils.saveViewToImage(getContext(), mBinding.llContent);
        dismiss();
    }

    //保存二维码
    public void onDownloadQRCode() {
        BitmapUtils.saveViewToImage(getContext(), mBinding.llQRCode);
        dismiss();
    }

    //微信好友
    public void onShareFriendsWx() {
        UMShareManager.getInstance().shareWx(activity, url, title, intro, new UMImage(context,shareLogo));
    }

    //微信朋友圈
    public void onShareFriendsPyq() {
        UMShareManager.getInstance().shareWxCirCle(activity, url, title, intro, new UMImage(context,shareLogo));
    }

    //支付宝好友
    public void onShareFriendsZfb() {
        UMShareManager.getInstance().shareAlipay(activity, url, title, intro, new UMImage(context,shareLogo));
    }

    //QQ好友
    public void onShareFriendsQq() {
        UMShareManager.getInstance().shareQQ(activity, url, title, intro, new UMImage(context,shareLogo));
    }

}